
package Timeline.Core.Menu;

import Timeline.Core.GameMain;
import Timeline.Jogador.Jogador;
import Timeline.Util.Cor.Cor;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ControlerMenuExterno implements ActionListener {
    
    private MenuExterno tela;
    private Jogador jogador;
    private ControlerMenuExterno(){
    }

    public ControlerMenuExterno(Jogador jogador) {
        this.jogador = jogador;
        iniciaTela();
        addListener();

    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == tela.btnIniciarJogo){
            gameStart();
            ConfigurarBotoes();
        }else if(e.getSource() == tela.btnOpcoes){
            mostraTela("cOpcoes");
            ConfigurarBotoes();
            
        }else if(e.getSource() == tela.btnVoltar){
            mostraTela("cPrincipal");  
            ConfigurarBotoes();
        }else if(e.getSource() == tela.btnSair){
            tela.dispose();
        }
        if(e.getSource() == tela.btnAplicar){
            if(tela.jCBCores.getSelectedItem().toString().equals("Branco")){
                Cor.cor = Color.WHITE;
            }
            if(tela.jCBCores.getSelectedItem().toString().equals("Amarelo")){
                Cor.cor = Color.YELLOW;
            }
            if(tela.jCBCores.getSelectedItem().toString().equals("Vermelho")){
                Cor.cor = Color.RED;
            }
            if(tela.jCBCores.getSelectedItem().toString().equals("Azul")){
                Cor.cor = Color.BLUE;
            }
            if(tela.jCBCores.getSelectedItem().toString().equals("Verde")){
                Cor.cor = Color.GREEN;
            }
            ConfigurarBotoes();
        }
    }

    private void iniciaTela() {
        tela = new MenuExterno();
        tela.setVisible(true);
    }

    private void addListener() {
        tela.btnCreditos.addActionListener(this);
        tela.btnIniciarJogo.addActionListener(this);
        tela.btnOpcoes.addActionListener(this);
        tela.btnVoltar.addActionListener(this);
        tela.btnSair.addActionListener(this);
        tela.btnAplicar.addActionListener(this);
    }

    public MenuExterno getTela() {
        return tela;
    }
    
    public void gameStart() {
       GameMain game = GameMain.getInstance();
       tela.setVisible(false);
       game.GameStart(jogador);
    }
    private void mostraTela(String nome){
        CardLayout card = (CardLayout) tela.pnlMenu.getLayout();
        card.show(tela.pnlMenu, nome); 
    }

    private void ConfigurarBotoes() {
        tela.btnInvisivel.setSelected(true);
    }
    
    
    
}
